C-Language

C Programming Language Tutorial: Introduction and Basics

The C programming language is a general-purpose, compiled language widely used for operating systems, embedded firmware, device drivers, compilers, and performance-sensitive software. It gives programmers explicit control over data representation and memory through pointers, while providing structured control flow, functions, and a standard library. C is not the same as C++; they share some syntax, but they are distinct languages with different language features and standards.

For embedded systems, C is valuable because it can work close to hardware and is supported by many microcontroller toolchains. However, the exact capabilities available to a firmware project depend on the compiler, target architecture, runtime library, and project coding rules. Embedded C is a common term for using C in embedded development; it is not a separate ISO C language standard.

A Small C Program

#include <stdio.h>

int main(void)
{
    printf("Hello, embedded world!\n");
    return 0;
}

This example uses the standard I/O library available in a hosted C environment. A microcontroller project may not provide a terminal or the full standard I/O implementation, so firmware examples often use a board-specific UART, debugger output, or another supported interface instead.

C was developed by Dennis Ritchie at Bell Labs in the early 1970s and was used in the development of Unix. It evolved from earlier languages including B. The book The C Programming Language by Brian Kernighan and Dennis Ritchie, published in 1978, became an influential description of the language, commonly associated with “K&R C.” Modern C is defined by ISO standards, so compiler behavior and available language features depend on the selected C standard and toolchain. C remains widely used for systems software, compilers, libraries, and embedded firmware.

  • It is easy to learn.
  • It is a Structure-oriented language.
  • It produces efficient programs.
  • It can handle low-level activities.
  • It can be compiled on a variety of computer platforms.
  • Much of Unix was implemented in C, alongside assembly language and platform-specific components.
  • Most of the state-of-the-art software has been implemented using C.
  • The Linux kernel is primarily written in C with architecture-specific assembly, while MySQL Server has historically been implemented largely in C++.

Why use C Language?

C is useful when software needs predictable control over data, memory, and execution. In embedded development, engineers use it for peripheral drivers, communication stacks, control logic, and real-time tasks. The best way to learn is to combine language fundamentals with small programs, compiler warnings, debugging, and target-specific documentation.

  • Operating Systems.
  • Compilers.
  • Assemblers.
  • C is widely used for embedded-system firmware. “Embedded C” usually describes C programming for embedded targets and project-specific constraints; it is not a separate ISO C language standard.
  • Text Editors.
  • Print Spoolers.
  • Network Drivers.
  • Modern Programs.
  • Databases.
  • Language Interpreters.
  • Utilities.

This tutorial introduces C programming concepts step by step, from basic syntax and data types to functions, pointers, and memory-related topics. For embedded projects, verify compiler behavior and target constraints rather than assuming every desktop C example will work unchanged on a microcontroller.

What Is Language?

Language is a medium of interaction between the two objects. It is a system of communication between any two objects either spoken or written. Humans have invented thousands of spoken languages to interact with other humans. The Birds, animals, insects, and every living creature interact in their own language. Whenever humans understood as they need help in their work without any human, they started the research and invented the machine. These machines are working for a human to help but they don’t have thinking capability to do like human. Only the machine can do the task which instructs by humans by using the electrical signals. Computers internally interact in the language of the low voltage and high voltage (known as binary). Among the different computer programming language, C language is one of them.

What is Programming Language?

A computer program is a set of instructions that a processor executes according to the system’s architecture and runtime environment. In embedded systems, firmware is typically stored in non-volatile memory such as Flash and executed by the microcontroller after startup. Instructions describe operations such as arithmetic, data movement, and control flow. A computer does not necessarily run every stored program at startup; the operating system or embedded startup code determines which software is loaded and executed. In a microcontroller, startup code typically initializes the runtime environment before transferring control to the application. Now we can say this is a method of the language of a computer to which the computer can understand what human wants by me or what task he wants from me to be done. So as humans are communicating with each other with different languages like Hindi, Odiya, English, etc. , the Machines are also having some languages made by a human so that the machines can also communicate with each other to work together. Through programming language, we can also communicate with the computer system. Why we are telling as programming language because normally the human need to program these instructions onto the computer so that they can start their work as per human expectation or interest. Since the computers are working with digital signals nothing but binary 1’s and 0’s, hence computers can only understand binary. These combinations of binary 0’s & 1’s are nothing but a language for computers or machines. but humans are not comfortable with the binary number system. Humans can not interact fluently with computers in the language of the 0’s and 1’s. The Programming language act as an interface between computers and humans. Programming languages are used to create programs. A computer program is intended to perform some specific tasks through the computer or to control the behavior of the computer. C remains important in systems software and embedded development because it offers direct control over data representation, memory access, and low-level interfaces while retaining portable language constructs.

Using the programming language, we write instructions that the computer should perform. Instructions are usually written using the characters, words, symbols, and decimal. These instructions are the later encoded to the computer understandable language i.e. binary language. So that the computer can understand the instructions given by humans and can perform a specified task.

Thousands of the programming languages have been created to date and many are still being developed every year. Every programming language is designed for some specific purpose. Such as FORTRAN, OCaml, Haskell are best suited for scientific and numerical computations. Whereas Java, C++, C# are best suited for designing server applications, games, desktop applications, and many more.

History of Programming Language

Earlier when there was no concept of the programming languages. Computer instructions are directly given to the computer in decimal or the binary format. These instructions are given through punch cards, magnetic tapes, or the through switches. Later on, when the computer started growing, more and more programs were written day-by-day. Writing programs completely in the binary was cumbersome and error-prone. Therefore, we developed various mnemonics for different instructions. These mnemonics are in a human-readable format. Such as ADD for adding values of two registers, SUB for subtracting for two registers, JMP for the conditional controls. Now, the programs were written using mnemonics and decimal values known as an assembly language. But remember this assembly language is not the C language, so we will discuss the c language later.

The Mnemonics are short abbreviated English words used to specify computer instruction. Each instruction in binary has a specific mnemonic. They are architecture-dependent and there is a list of separate mnemonics for the different computer architectures. Mnemonics gave relief to the programmers from writing programs directly in the binary language. However, it was still a tedious work to remember the complete list of mnemonics for the various computer architectures.

Classification of Programming Languages

Since the computers are understanding only digital binary 1’s & 0’s as their language for their understanding, it was very difficult for humans always to write in the binary. We are also not interested to learn again a different difficult language for computer programming. so we started investing in programming so that the language with which we are talking to each other, we can also use this for computer programming. There are thousands of programming languages have been written to date. Each for some specific purpose. Some of the programming languages provide less or no abstraction from the hardware. Whereas some provide higher abstraction. To separate programming languages on the basis of the level of abstraction from hardware, they are classified into various categories. The Programming languages are basically classified into two main categories – Low-level language and High-level language. However, some educational resources informally describe C as a “middle-level” language because it combines structured programming constructs with low-level memory and bitwise operations. This is an informal teaching label, not a formal category defined by the C standard. The following sections explain these classifications and why C is sometimes informally described as a middle-level language.

Whenever you will write any program, you should select a language to write the program. Generally, it is divided into 3 types are:

  1. Low-Level Language.
  2. Medium-Level Language.
  3. High-Level Language.
C language level
C language level

Low-Level Language

Medium-Level Language

High-Level Language

Features Of C Programming

  • General Purpose Language
  • Procedural Language
  • Middle Level Language
  • Easy to Extend
  • Portability
  • Libraries with rich functions
  • Rich set of build-in functions
  • Statically type
  • Modularity
  • Fast and Efficient

C-Programming Compilation process

When you are writing a program in a high-level language, obviously you need to convert it into machine level language.

What is Function in C?

In C, a function is a named block of code that performs a specific task. A hosted C program normally defines a function named main() as its entry point. Freestanding implementations, such as some embedded firmware environments, can use implementation-defined startup arrangements and may not provide the same hosted execution model. Programs can be divided into additional functions to make responsibilities clearer and code easier to test and maintain. You can divide a program into separate functions, with each function responsible for a clear, specific task. How you divide up your code among different functions is up to you, but logically the division is such that each function performs a specific task. A function declaration tells the compiler about the function’s name, return type, and parameters. A function definition provides the actual body of the function. The C standard library provides numerous built-in functions that your program can call. For example, strcat() to concatenate two strings, memcpy() to copy one memory location to another location, and many more functions. A function can also be referred to as a method or a sub-routine or a procedure, etc.

What is the Control statement in C Language?

C is a computer programming language. That means that you can use the C language to create lists of instructions for a computer to follow. C is one of the thousands of programming languages currently in use. The arithmetic operator is used for mathematical calculation these operators are the binary operator that works with integer floating-point number and every character. :Arithmetical operator are: Operator Meaning + Addition – Subtraction * Multiplication / Division % Module division. The relational operator is used to comparing two operands. Operands may be variable, constant, or expression. Operator Meaning < Is less than <= Is less than equal to > Is greater than >= Is greater than equal to == Equal to != is not equal to For example, the standard C expression `a > b` evaluates to 1 when a is greater than b and 0 otherwise. In portable examples, declare variables inside a function and use standard headers; `getch()` is not part of the ISO C standard library. Are used to combine (compare) two or more condition.Logical Operator are:- Operator Meaning && Logical AND || Logical OR! Logical NOT.

Control Statements Type in C Language

There are 3 types of control statements in c language.

  1. Conditional or decision control statement.
  2. Loop or iterative control statement.
  3. Jumping Control Statements.

Loop or Iterative Control Statement

Looping is the most important concept in the C-programming language. It means executing the same statement or block of statements repeatedly several times based on certain conditions. More precisely, the loop keeps on executing as long as the condition is true. It helps a lot to the programmer in saving his time and processor execution time. There are two parts of the loop such as the body of the loop and the control statement. The control statement is the condition that directs the body of the loop to execute the statement as long as the condition is true.

Why Loop Control is important?

Suppose you want to execute the message “hello India” for 100 times at one go. For which You have to write the same statement 100 times sequentially. The result of which is very time consuming and very difficult for the programmer to finish it. Most importantly, the whole program becomes bulky and confusing to understand immediately. So, the scientist added a new concept called the “loop construct concept”. It makes it easy to write reliable coding. In addition, the loop construct cuts the number of same statements and frames them into one statement to execute the output several times as per the terminating condition.

Types of Loop Control Statements in C

There are two types of loop or iterative control statements in the C programming language. one is a finite control statement and another is infinite control statement. Again the infinite control statement is categorized into two types, one is while loop and another one is the do-while loop control statement. as a result, we can say there are 3 types of loop control statements in the C programming language. To learn any of the loop control statements you need to select the below links.

  1. For Loop Control Statement.
  2. While Loop Control Statement.
  3. Do-While Loop Control Statement.

What is an Array in C?

Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type in C language. An array is used to store a collection of the data, but it is often more useful to think of an array as a collection of variables of the same type. Instead of declaring individual variables, such as number0, number1, …, and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and …, numbers[99] to represent individual variables. A specific element in an array is accessed by an index. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address of the last element. Arrays in C Declaring Arrays To declare an array in C, a programmer specifies the type of the elements and the number of the elements required by an array as follows − type arrayName [ arrays ]; This is called a single-dimensional array. The array size must be an integer constant greater than zero and type can be any valid C the data type. For example, to declare a 10-element array called the balance of the type double, use this statement.

What is Pointer in C Language?

Pointers in the C are easy and fun to learn. In C language some C programming tasks are performed more easily with pointers, and other tasks, such as dynamic memory allocation, cannot be performed without using pointers. So it becomes necessary to learn pointers to become a perfect C programmer. Let’s start learning them in simple and easy steps. A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address. The general form of a pointer variable declaration is − type *var-name; Here, a type is the pointer’s base type; it must be a valid C data type and var-name is the name of the pointer variable. The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement, the asterisk is being used to designate a variable as a pointer. Take a look at some of the valid pointer declarations.

What is String in C Language?

In C language, strings are actually one-dimensional array of the characters terminated by a null character ‘\0’. Thus a null-terminated string contains the characters that comprise the string followed by a null. The following declaration and initialization create a string consisting of the word “Hello”. To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of the characters in the word “Hello.”

What is Structure and Union in c?

In C language, Arrays allow defining types of variables that can hold several data items of the same kind. Similarly, the structure is another user-defined data type available in C that allows combining data items of different kinds. Structure in c language is a user-defined datatype that allows you to hold a different type of elements. Each element of the structure is called a member. It works as a template in C++ and class in Java. You can have different types of elements in it. It is widely used for the store student information, employee information, product information, book information, etc.

File Handling in C?

File Handling in C language is used to the open, read, write, search, or close the file. It is used for permanent storage. A file represents a sequence of the bytes, regardless of it being a text file or a binary file. A c programming language provides access to the high-level functions as well as low level (OS level) calls to the handle file on your storage devices. This chapter will take you through to the important calls for file management.

What is Pre-processor in C?

The C Preprocessor is not a part of the compiler but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before to the actual compilation. We’ll refer to the C Preprocessor as CPP. All preprocessor commands begin with the hash symbol (#). It must be the first nonblank character, and for the readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives 

Basics Understanding of C Programming Language

Control Statements in C Programming Language

Functions in C Programming Language

Array in C Programming Language

Pointers in C Programming Language

Dynamic Memory in C Programming Language

Strings in C Programming language

Math in C Programming Language

Structure Union in C Programming Language

File Handling in C Programming Language

Preprocessor C in Programming Language

Command Line in C Programming Language

Misc in C Programming Language

4 thoughts on “C-Language”

  1. swarup kumar nath

    I have never ever seen the tutorial like this. Thank you PiEmbSysTech for clearing my doubt

Leave a Reply

Scroll to Top